package com.plian.system.service.sys.bigdata.Materia;

import com.alibaba.fastjson.JSONObject;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.entity.fr.procurement.MaterialProcurement;
import com.plian.system.mapper.fr.procurement.MaterialProcurementMapper;
import com.plian.system.vo.fr.procurement.MaterialProcurementVO;
import com.plian.system.wrapper.fr.procurement.MaterialProcurementWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author huzb
 * @create 2020-10-21 15:34
 */
@Slf4j
@Service
@AllArgsConstructor
public class MaterinfoService {

    MaterialProcurementMapper materialProcurementMapper;

    MaterialProcurementWrapper materialProcurementWrapper;

    /**
     *  新创建的对象list
     * @param json
     * @return
     */
    public List<PageData> findListByDateRange(String json)  {
        List<PageData> listByDateRange = new ArrayList<>();
        try {
            PageData pageData = new PageData();
            JSONObject jsonObject = JSONObject.parseObject(json);
            String starttime = jsonObject.getString("startTime");
            String endtime = jsonObject.getString("endTime");
            pageData.put("startTime",starttime);
            pageData.put("endTime",endtime);
            List<MaterialProcurement> materialProcurements = materialProcurementMapper.MaterByTime(pageData);
            listByDateRange = MaterVOToPageData(materialProcurements);
        } catch (Exception e) {
            log.error(ExceptionUtils.getFullStackTrace(e));
        }
        return listByDateRange;
    }


    public  List<PageData> MaterVOToPageData(List<MaterialProcurement> materialProcurements){
        List<PageData> listByDateRange = new ArrayList<>();
        List<MaterialProcurementVO> materialProcurementVOS = materialProcurementWrapper.entityToVO(materialProcurements);
        for (MaterialProcurementVO vo:materialProcurementVOS){
            PageData pd = new PageData();
            pd.put("fillingUnitName",vo.getFillingUnitName());
            pd.put("fillingYear",vo.getFillingYear());
            pd.put("procurementCompanyName",vo.getProcurementCategoryName());
            pd.put("procurementCompanyRankName",vo.getProcurementCompanyRankName());
            pd.put("procurementProject",vo.getProcurementProject());
            pd.put("procurementCategoryName",vo.getProcurementCategoryName());
            pd.put("procurementPlatformCategoryName",vo.getProcurementPlatformCategoryName());
            pd.put("procurementPlatform",vo.getProcurementPlatform());
            pd.put("procurementWayName",vo.getProcurementWayName());
            pd.put("procurementContractAmount",vo.getProcurementContractAmount());
            pd.put("procurementCoverCharge",vo.getProcurementCoverCharge());
            pd.put("budget",vo.getBudget());
            pd.put("qualityProductsProcurement",vo.getQualityProductsProcurement());
            pd.put("supplier",vo.getSupplier());
            pd.put("innovationProductsProcurement",vo.getInnovationProductsProcurement());
            pd.put("creditEnterprisesProcurement",vo.getCreditEnterprisesProcurement());
            pd.put("agencyName",vo.getAgencyName());
            listByDateRange.add(pd);
        }
        return  listByDateRange;
    }

}
